package com.org.cn.action;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionContext;
import com.org.cn.action.base.BaseActionSupport;
import com.org.cn.bean.UserInfo;
import com.org.cn.bean.base.PageView;
import com.org.cn.service.user.IUserInfoService;

@SuppressWarnings("serial")
public class UserInfoAction extends BaseActionSupport {

	private IUserInfoService userInfoService;

	public void setUserInfoService(IUserInfoService userInfoService) {
		this.userInfoService = userInfoService;
	}
	
	public String findByEntity(){
		ActionContext ctx = ActionContext.getContext();
		HttpServletRequest request = (HttpServletRequest) ctx.get(ServletActionContext.HTTP_REQUEST);
		int maxResult = 5;

		PageView<UserInfo> pageView = new PageView<UserInfo>(maxResult, getPage());
		
		/**
		 * 下面修改service即可
		 */
		pageView.setQueryResult(userInfoService.getScrollData(pageView.getFirstResult(), maxResult));
		
		/**
		 * request.setAttribute("pageView", pageView)中key尽量为pageView，不然需要修改代码
		 */
		request.setAttribute("pageView", pageView);
		
		return SUCCESS;
	}
	
}
